package com.usian.admin.controller;

import com.usian.admin.service.TbAdminService;
import com.usian.apis.admin.AbAdminControllerApi;

import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.zuoye.taadmin01.TbAdmin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Controller
@RequestMapping("admin/go")
public class TbAdminController {
    @Autowired  TbAdminService tbAdminService;

    @PostMapping("findAll")
    public String findAll(String name, Model model){
        List<TbAdmin> all = tbAdminService.findAll(name);
        model.addAttribute("admin",all);
        return "index";
    }
    @GetMapping("findById")
    public String findById(String name,Integer id,Integer state,Model model){
        tbAdminService.findById(name,id,state);
        List<TbAdmin> all = tbAdminService.findAll(null);
        model.addAttribute("admin",all);
        return "index";
    }
    @RequestMapping("edit")
    public String edit(String realname,Integer id){
        tbAdminService.update(realname,id);
        return "redirect:/admin/go/findAll";
    }

    @RequestMapping("update")
    public String findById(Integer id, Model model){
        TbAdmin stu = tbAdminService.findById(id);
        model.addAttribute("stu",stu);
        return "update";
    }

}